#define _CRT_SECURE_NO_WARNINGS 1
/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
public:
    bool chkPalindrome(ListNode* A) {
        struct ListNode* slow, * fast;
        slow = fast = A;
        while (fast && fast->next) {
            slow = slow->next;
            fast = fast->next->next;
        }

        struct ListNode* head = slow;
        if (head == NULL)
            return NULL;
        struct ListNode* n1 = NULL;
        struct ListNode* n2 = head;
        struct ListNode* n3 = head->next;
        while (n2) {
            n2->next = n1;

            n1 = n2;
            n2 = n3;
            if (n3)
                n3 = n3->next;
        }
        head = n1;
        while (head)
        {
            if (head->val == A->val)
            {
                head = head->next;
                A = A->next;
            }
            else {
                return false;
            }
        }
        return true;
    }
};